﻿using PJTY.dal;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

public partial class views_customer_tz : System.Web.UI.Page
{
    DataClasses1DataContext db = new DataClasses1DataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        string productName = Request.QueryString["ProductName"];
        
        int[] scores = (from dr in db.Review where dr.ProductName.ToString() == productName select Convert.ToInt32(dr.ReviewScore)).ToArray();
        int[] ages = (from dr in db.Review where dr.ProductName.ToString() == productName select Convert.ToInt32(dr.ConsumerAge)).ToArray();
        int goodCount = (from dr in db.Review where dr.ProductName.ToString() == productName && Convert.ToInt32(dr.ReviewScore) > 3 select dr).Count();
        int mediumCount = (from dr in db.Review where dr.ProductName.ToString() == productName && Convert.ToInt32(dr.ReviewScore) == 3 select dr).Count();
        int badCount = (from dr in db.Review where dr.ProductName.ToString() == productName && Convert.ToInt32(dr.ReviewScore) < 3 select dr).Count();
        double avgScore = scores.Average();
        double avgAge = ages.Average();
        Label3.Text = "商品名称：" + productName;
        Label2.Text = "平均分数：" + avgScore.ToString("0.00")+"(最高分为5分)";
        Label4.Text = "好评数量：" + goodCount.ToString();
        Label5.Text = "中评数量：" + mediumCount.ToString();
        Label6.Text = "差评数量：" + badCount.ToString();
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        string productName = Request.QueryString["ProductName"];
        LinqDataSource1.WhereParameters.Clear();
        LinqDataSource1.WhereParameters.Add("ProductName", TypeCode.String, productName);
        LinqDataSource1.WhereParameters.Add("ReviewScore", TypeCode.Int32, "3");
        LinqDataSource1.Where = "ProductName == @ProductName && ReviewScore > @ReviewScore";
        rptReviews.DataSource = LinqDataSource1;
        rptReviews.DataBind();
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string productName = Request.QueryString["ProductName"];
        LinqDataSource1.WhereParameters.Clear();
        LinqDataSource1.WhereParameters.Add("ProductName", TypeCode.String, productName);
        LinqDataSource1.WhereParameters.Add("ReviewScore", TypeCode.Int32, "3");
        LinqDataSource1.Where = "ProductName == @ProductName && ReviewScore == @ReviewScore";
        rptReviews.DataSource = LinqDataSource1;
        rptReviews.DataBind();
    }

    protected void Button3_Click(object sender, EventArgs e)
    {
        string productName = Request.QueryString["ProductName"];
        LinqDataSource1.WhereParameters.Clear();
        LinqDataSource1.WhereParameters.Add("ProductName", TypeCode.String, productName);
        LinqDataSource1.WhereParameters.Add("ReviewScore", TypeCode.Int32, "3");
        LinqDataSource1.Where = "ProductName == @ProductName && ReviewScore < @ReviewScore";
        rptReviews.DataSource = LinqDataSource1;
        rptReviews.DataBind();
    }

    protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {

    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        Response.Redirect("sppj.aspx");
    }
}